<?php

require_once 'JSCasts/Path/Interface.php';

class JSCasts_Path_Abstract
implements JSCasts_Path_Interface
{
    protected $components = array();
    protected $delimiter;
    
    public function __construct($pathString)
    {
        $this->components = explode($this->delimiter, trim($pathString, $this->delimiter));
    }
    
    public function __toString()
    {
        return implode($this->delimiter, $this->components);
    }

    public function component($index, $newValue = false)
    {
        if (array_key_exists($index, $this->components)) {
            if ($newValue !== false) {
                $this->components[$index] = $newValue;
            }
            
            return $this->components[$index];
        }
        
        return null;
    }
}